<?php

/**
 * Time Class
 * 
 * @author    Werner Pallentin <werner.pallentin@outlook.de>
 * @package   System
 */
class Time {

  /**
   * pluralize
   *
   * @param <string> $count        	
   * @param <beliebig> $text
   */
  public function pluralize($count, $text) {
    $v = $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}en" ) );
    return str_replace("een", "en", $v);
  }

  /**
   * Anzeige der letzten Updateaktion
   * @param <string> $datetime        	
   */
  public function ago($datetime) {
    $interval = date_create('now')->diff($datetime);
    $suffix = ( $interval->invert ? texte::getText('time_ago_vor').' ' : '' );
    //$suffix = ( $interval->invert ? 'vor ' : '' );

    if ($v = $interval->y >= 1)
      return $suffix . $this->pluralize($interval->y, texte::getText('time_ago_jahr'));
    if ($v = $interval->m >= 1)
      return $suffix . $this->pluralize($interval->m, texte::getText('time_ago_monat'));
    if ($v = $interval->d >= 1)
      return $suffix . $this->pluralize($interval->d, texte::getText('time_ago_tag'));
    if ($v = $interval->h >= 1)
      return $suffix . $this->pluralize($interval->h, texte::getText('time_ago_stunde'));
    if ($v = $interval->i >= 1)
      return $suffix . $this->pluralize($interval->i, texte::getText('time_ago_minute'));

    return $suffix . $this->pluralize($interval->s, texte::getText('time_ago_sekunde'));
  }

}
